// pages/shippingAddress/shippingAddress.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addressList:[],   //查询的收货地址列表
  },
  // 添加收货地址
  addAddress(){
    wx.navigateTo({
      url: '/pages/addAddress/addAddress'
    })
  },
  // 查询收货地址列表
  getaddressList(){
    var that = this
    wx.request({
      url: getApp().globalData.baseUrl + '/wago/address/select',
      data: {
        userid:getApp().globalData.openid,
        page:1,
        size:100
      },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        console.log('res',res.data.data)
        if(res.data.flag){
          that.setData({
            addressList:res.data.data
          })
          var addlist = that.data.addressList
          for(var i = 0;i < addlist.length;i++){
            addlist[i].namefirst = addlist[i].name.slice(0,1)
          }
          that.setData({
            addressList:addlist
          })
        }
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  toedit:function(e){
    // console.log('1111',e.currentTarget.dataset)
    
    wx.navigateTo({
      url:"/pages/editAddress/editAddress?name="+e.currentTarget.dataset.name +"&phone="+e.currentTarget.dataset.phone
          +"&address="+ e.currentTarget.dataset.address + "&addressid="+e.currentTarget.dataset.addressid
          + "&prefer=" + e.currentTarget.dataset.prefer
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getaddressList()
  },
   /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    //跳转指定页
    wx.reLaunch({
      url: '/pages/personal/personal'
    })
  },
})